i.atcorr: Fix out-of-bounds array access in trunca computations#3909
i.atcorr: Fix out-of-bounds array access in trunca computations#3909ShubhamDesai wants to merge 6 commits intoOSGeo:mainfrom
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
@YannChemin Would this minor change to |
|
@ShubhamDesai Check this suggestion from ChatGPT: https://chatgpt.com/share/66f18923-0348-8009-bf2a-e415c5ae9a89 With or without that suggestion, this PS seems like it will require a regression test to make sure we are not breaking this. Can you write one in a separate PR? Either pytest style you used before for g.version (but with use of, e.g., r.univar to get raster values) or it might be easier to follow the unittest style with existing dataset like e.g., https://github.com/OSGeo/grass/blob/main/vector/v.surf.rst/testsuite/test_vsurfrst.py (check the assertVectorFitsUnivar calls). We can discuss in more detail when we meet. |
Sure I will write the regression test for it. |
|
I'm not sure what tool reports this as out-of-bounds array access. However, grass/imagery/i.atcorr/computations.cpp Lines 108 to 113 in 2e55b15 make it clear it must be between 0 and 82. |
This pull request fixes several instances of out-of-bounds array access in the
computations.cppfile within thei.atcorrmodule. Specifically, it addresses issues where negative indices were being used to access arrays, which could lead to undefined behavior and potential crashes.Changes Made
if (kk < 0) kk = 0;
Issues Resolved
Error : Array sixs_trunc.pha[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:116:39
Details : (double)((log10(sixs_trunc.pha[kk]) - log10(sixs_trunc.pha[k])) /
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:116:39
Details : (double)((log10(sixs_trunc.pha[kk]) - log10(sixs_trunc.pha[k])) /
Error : Array rmu[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:117:27
Details : (acos(rmu[kk]) - acos(rmu[k])));
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:117:27
Details : (acos(rmu[kk]) - acos(rmu[k])));
Error : Array sixs_trunc.pha[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:118:46
Details : double x1 = (double)(log10(sixs_trunc.pha[kk]));
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:118:46
Details : double x1 = (double)(log10(sixs_trunc.pha[kk]));
Error : Array rmu[83] accessed at index -1, which is out of bounds.
Location : imagery/i.atcorr/computations.cpp:119:33
Details : double x2 = (double)acos(rmu[kk]);
Error : Assuming condition is false
Location : imagery/i.atcorr/computations.cpp:110:20
Details : if (rmu[i] > 0.94)
Error : Assignment 'kk=i-1', assigned value is -1
Location : imagery/i.atcorr/computations.cpp:112:16
Details : kk = i - 1;
Error : Negative array index
Location : imagery/i.atcorr/computations.cpp:119:33
Details : double x2 = (double)acos(rmu[kk]);